*TITLE:INCUMBENT TENURE CROWDS OUT ECONOMIC VOTING
*JOURNAL: BRITISH JOURNAL OF POLITICAL SCIENCE
*AUTHOR: MARTIN VINÆS LARSEN
*FILE: COUNTRY-LEVEL ANALYSES
*DEPENDENCIES: eststo, lmoments, blindschemes, combomarginsplot

*loading dataset*
use "country.dta", clear

//DATA DESCRIPTION IN MANUSCRIPT//

*Effective sample is 41 countries and 409 elections
ta ccode if time!=. 

*Median of time in office variable is 5 and mean is 6 years.
su time, d

*number of incumbents and number of incumbents in the UK
ta a1
ta a1 if ccode==236


//TABLE 1//
label var delta_i "%nowrite"
label var incvotet2 "Lagged Support"

*models
eststo  a: mixed delta_i  c.grow##(c.time) incvotet2 exec  , vce(cluster ccode)
eststo  b: mixed delta_i  c.grow##(c.time) incvotet2 exec i.year, vce(cluster ccode)
eststo  c: mixed delta_i c.grow##(c.time) incvotet2 exec i.year   i.ccode, vce(cluster ccode)
eststo  d: mixed delta_i  c.grow##(c.time) incvotet2 exec i.ccode i.a1, vce(cluster ccode)

*table
esttab a b c d using aggtable.tex, replace keep(grow time c.grow#c.time exec incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label( "Observations") fmt(%9.0fc) ) ///
indicate("\hline Year  FE=1988.year" " Country FE = 110.ccode" "Leader FE= 68.a1", labels("$\checkmark$" " ")) ///
label se nomtitles title(Linear Regression of Changes in Executive Party Vote Share} \footnotesize \label{table:agg) nonotes ///
addnotes( "Standard errors clustered by country in parentheses.") nogaps nodepvar

//FIGURE 1//

est restore d //restoring model from table 1 column 4

*marginal effects
margins, dydx(grow) at(time=(0(1)15)) post coeflegend

*graph
marginsplot, level(95) scheme(plotplain)  legend(off) ///
addplot(histogram time if e(sample)==1 & time < 16,  yaxis(2)  yscale(off axis(2)) percent  ylabel(0 60, axis(2))  ///
discret  lcolor(black*0.5) fcolor(white) ylabel( -1 -0.5 0 0.5 1 1.5, axis(1) labsize(medlarge)) xlabel(0(4)16, labsize(medlarge)) below) ///
xtitle(" " "Years in Office", size(large)) ytitle("Effect of Economic Growth" " ", size(large)) graphregion(color(white)) ///
legend(off) plotopts(lwidth(thick))title(" ")   yline(0) recastci(rline) recast(line)
 graph export fig1clevel.eps, replace


////////////////APPENDIX///////////////////////////////
*S2 Sample Description
eststo am: estpost tabstat year if time!=., by(ccode) stats(min max n)
esttab am using sampledesclevel.tex, replace cells("min(fmt(0) label(Minimum)) max(fmt(0) label(Maximum)) count(fmt(0) label(Number of Elections))") ///
title(Elections Included in the Country-level Analysis} \footnotesize \label{sammac) nomtitles noobs  nonumber nostar nonotes


*S3 Descriptive statistics
preserve
drop year ccode a1 trich _e*
label var grow "Economic growth" 
label var delta "Change in support for incumbent party" 

file open anyname using aggdes.txt, write text replace
file write anyname  _newline  _col(0)  "\begin{table}[htbp] \footnotesize \centering \caption{Descriptive Statistics, Country-level Data} \label{descount} \begin{tabular}{l*{10}{c}}\hline\hline"
file write anyname _newline _col(0) "&Mean & SD & Min& Max& n \\  \hline "
foreach x of varlist * {
su `x'  , d
file write anyname _newline (`"`: var label `x''"') "  &" _tab %9.2f  (r(mean)) " &" _tab %9.2f (r(sd)) " &" _tab %9.2f  (r(min)) " &" _tab %9.2f  (r(max)) " &" _tab %9.0f  (r(N)) " \\"
}
file write anyname _newline _col(0) "\hline\hline"
file write anyname _newline _col(0) "\end{tabular}"
file write anyname _newline _col(0) "\end{table}"
file close anyname
restore
*

 
*Alternative growth measure (S4)
eststo  a: mixed delta_i c.gr_2yr##(c.time) incvotet2 exec  , vce(cluster ccode)
eststo  b: mixed delta_i c.gr_2yr##(c.time) incvotet2 exec i.year, vce(cluster ccode)
eststo  c: mixed delta_i c.gr_2yr##(c.time) incvotet2 exec i.year i.ccode, vce(cluster ccode)
eststo d: mixed delta_i  c.gr_2yr##(c.time) incvotet2 exec i.ccode i.a1, vce(cluster ccode)

label var delta_i "%nowrite"
esttab a b c d using apdxaltgrwth.tex, replace keep(gr_2yr time c.gr_2yr#c.time exec incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label( "Observations") fmt( %9.0fc) ) ///
indicate("\hline Year  FE=1988.year" " Country FE = 110.ccode" "Leader FE= 68.a1", labels("$\checkmark$" " ")) ///
label se nomtitles title(Alternative Measure of Economic Growth} \footnotesize \label{table:altgrowth) nonotes ///
addnotes( "Standard errors clustered by country in parentheses.") nogaps nodepvar
 
 
*Control variables (S5)
eststo  a: mixed delta_i exec c.grow##(c.time) incvotet2 if majgov!=. & govoth!=. & enlp!=., vce(cluster ccode)
eststo  b: mixed delta_i exec c.grow##(c.time) incvotet2 i.year   if majgov!=. & govoth!=. & enlp!=., vce(cluster ccode)
eststo  c: mixed delta_i exec c.grow##(c.time) incvotet2 i.year i.ccode  if majgov!=. & govoth!=. & enlp!=., vce(cluster ccode)
eststo  d: mixed delta_i exec c.grow##(c.time) incvotet2 i.ccode i.a1  if majgov!=. & govoth!=. & enlp!=., vce(cluster ccode)
eststo  e: mixed delta_i exec c.grow##(c.time) incvotet2  majgov i.govoth enlp, vce(cluster ccode)
eststo  f: mixed delta_i exec c.grow##(c.time) incvotet2 i.year   majgov i.govoth enlp, vce(cluster ccode)
eststo  g: mixed delta_i exec c.grow##(c.time) incvotet2 i.year i.ccode  majgov i.govoth enlp, vce(cluster ccode)
eststo  h: mixed delta_i exec c.grow##(c.time)  incvotet2 i.ccode i.a1  majgov i.govoth enlp, vce(cluster ccode)

esttab a b c d e f g h using controls.tex, replace keep(grow  time c.grow#c.time enlp majgov 1.govoth 2.govoth 3.govoth exec incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label("Observations") fmt( %9.0fc) ) ///
indicate("\hline Time  FE=1988.year" " Country FE = 110.ccode" "Leader FE= 68.a1", labels("$\checkmark$" " ")) ///
label se nomtitles title(Including Control Variables in the Country-level Data} \footnotesize \label{table:controls) nonotes ///
addnotes( "Standard errors clustered by country in parentheses.") nogaps   ///
varlabel(1.govoth "One coalition partner" 2.govoth "Two coalition partners" 3.govoth "More than two coalition partners")

*Sensitivity to outliers (S6)
preserve
decode ccode, gen(secheck)
encode secheck, gen(secheck_num)
ta secheck_num, nol
tempfile temp1
postfile results id m1 m2 m3 m4 using `temp1', replace
forvalues i=0/41{
qui{
mixed delta_i c.grow##(c.time) exec incvotet2 if secheck_num!=`i', vce(cluster ccode)
 local b1=_b[c.grow#c.time]
mixed delta_i c.grow##(c.time) exec incvotet2 i.year if secheck_num!=`i', vce(cluster ccode)
local b2=_b[c.grow#c.time]
mixed delta_i c.grow##(c.time)  exec incvotet2 i.year i.ccode if secheck_num!=`i', vce(cluster ccode)
local b3=_b[c.grow#c.time]
mixed delta_i c.grow##(c.time)  exec incvotet2 i.a1 if secheck_num!=`i', vce(cluster ccode)
local b4=_b[c.grow#c.time]
post results (`i') (`b1') (`b2') (`b3') (`b4')
}
di `i'
}
postclose results
use `temp1', clear
reshape long m, j(modelnr) i (id) 
gen pipe="|"
twoway scatter modelnr m if id!=0, msym(Oh) mcolor(black*0.7) msize(medlarge) ///
|| scatter modelnr m if id==0, scheme(plotplain) msym(none) mlab(pipe) mlabsize(vlarge) msize(large) ///
 xlabel(-0.1(0.02)0.00, labsize(medlarge)) ///
 ylabel(0.75 " "  1 "Model 1" 2 "Model 2 - Year FE " 3 "Model 3 - Year, Country FE " ///
 4 "Model 4 -  Leader FE " 3.25 " ", labsize(medlarge) notick angle(0)) legend(off) ///
 xtitle(" " "Estimated intereaction (Country-level)", size(medlarge)) ytitle(" ")
 graph export apd_outlierclvl.eps, replace
restore


*Sensitivity of interaction (S7)
lmoments time
tabstat time, stats(p50) by(trich)
recode trich 0=4 1=6 2=12
gen time2=time-4 if trich==4
replace time2=time-6 if trich==6
replace time2=time-12 if trich==12
tempfile temp1 temp2
mixed delta_i (c.time2 c.grow c.grow#c.time2)##trich exec, vce(cluster ccode)
margin, dydx(grow) at(trich=(4 6 12)) saving(`temp1') level(95) post
mixed delta_i c.grow##c.time exec , vce(cluster ccode)
margin, dydx(grow) at(time=(1(1)15)) saving(`temp2') level(95)

preserve
use `temp1', clear
append using `temp2'
gen id=0
replace id=1 if _n >3
twoway line  _margin _at2 if id==1, lwidth(medthick) || ///
scatter _margin _at3 if id==0, msym(O) msize(medlarge) mcolor(black) || ///
rline _ci_lb _ci_ub _at2 if id==1, lcolor(black) || ///
rspike _ci_lb _ci_ub _at3 if id==0, scheme(plotplain) lcolor(black) yline(0) ylab(,labsize(medlarge)) xlab(,labsize(medlarge)) ///
legend(off) xtitle(Years in Office, size(medlarge)) ytitle(Effect of Economic Growth , size(medlarge))
graph export apd_clevelhein.eps, replace
restore


*Election Timing (S8)
eststo a: mixed delta_i  c.grow##(c.time) c.term incvotet2 exec, vce(cluster ccode)
eststo b: mixed delta_i  c.grow##(c.time) c.term incvotet2 exec i.year, vce(cluster ccode)
eststo c: mixed delta_i  c.grow##(c.time) c.term incvotet2 exec  i.ccode i.yea, vce(cluster ccode)
eststo d: mixed delta_i  c.grow##(c.time) c.term incvotet2 exec i.a1 i.ccode, vce(cluster ccode)
eststo e: mixed delta_i  c.grow##c.time  incvotet2  exec if  fixed==1, vce(cluster ccode)
eststo f: mixed delta_i  c.grow##c.time i.year incvotet2 exec if  fixed==1, vce(cluster ccode)
eststo g: mixed delta_i  c.grow##c.time i.ccode incvotet2  i.year exec  if  fixed==1, vce(cluster ccode)
eststo h: mixed delta_i  c.grow##c.time i.ccode incvotet2 i.a1   if  fixed==1, vce(cluster ccode) 

esttab a b c d e f g h using electime.tex, replace keep(grow time c.grow#c.time exec incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label("Observations") fmt( %9.0fc) ) ///
indicate("\hline Time  FE=1988.year" " Country FE = 54.ccode" "Leader FE= 46.a1", labels("$\checkmark$" " ")) ///
label se nomtitles title(Controlling for Election Timing} \footnotesize \label{table:fixed) ///
nonotes addnotes("Standard errors clustered by country in parentheses." "Executive election dummy omitted in column eight due to perfect collinearity with Leader FE.") nogaps

*Coalition governments (S9)
preserve
drop if exec==1
recode govoth (0=0) (1/4=1), gen(dual)
la var dual "Coalition"
tempvar tempa1 tempa2
gen `tempa1'=1
gen `tempa2'=2
eststo  a: mixed delta_i c.grow##(c.time) incvotet2  if dual==0 , vce(cluster ccode)
eststo  b: mixed delta_i c.grow##(c.time) incvotet2 i.year if dual==0, vce(cluster ccode)
eststo  c: mixed delta_i c.grow##(c.time) incvotet2 `tempa1'  i.year i.ccode if dual==0, vce(cluster ccode)
eststo d: mixed delta_i  c.grow##(c.time) incvotet2 `tempa1' `tempa2'  i.ccode i.a1 if dual==0, vce(cluster ccode)
eststo  e: mixed delta_i c.grow##(c.time) incvotet2   if dual==1 , vce(cluster ccode)
eststo  f: mixed delta_i c.grow##(c.time) incvotet2  i.year if dual==1, vce(cluster ccode)
eststo  g: mixed delta_i c.grow##(c.time) incvotet2 `tempa1'  i.year i.ccode if dual==1, vce(cluster ccode)
eststo h: mixed delta_i c.grow##(c.time) incvotet2 `tempa1' `tempa2' i.ccode i.a1 if dual==1, vce(cluster ccode)

esttab a b c d e f g h using dual.tex, replace keep(grow time c.grow#c.time incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label( "Observations") fmt(%9.0fc) ) ///
indicate("\hline Time  FE=1988.year" " Country FE = __000000" "Leader FE= __000001", labels("$\checkmark$" " ")) ///
label se nomtitles title(Differences Between Single-Party and Multi-Party Governments in the Country-level Data} \footnotesize \label{table:dual) ///
nonotes addnotes("Standard errors clustered by country in parentheses.") nogaps
restore

*Mismatch in tenure (S10)
eststo  a: mixed delta_i (c.dif c.grow)##(c.time)  exec incvotet2, vce(cluster ccode)
eststo  b: mixed delta_i (c.dif c.grow)##(c.time)  exec incvotet2  i.year , vce(cluster ccode)
eststo  c: mixed delta_i (c.dif c.grow)##(c.time)  exec incvotet2  i.year i.ccode, vce(cluster ccode)
eststo  d: mixed delta_i  (c.dif c.grow)##(c.time)  exec incvotet2  i.ccode i.a1 , vce(cluster ccode)

esttab a b c d using apdxdif.tex, replace keep(grow time c.grow#c.time  c.dif#c.time exec dif incvotet2) star(+ 0.10 * 0.05) b(%9.2fc) ///
stats(N, label( "Observations") fmt(%9.0fc) ) ///
indicate("\hline Year  FE=1988.year" " Country FE = 110.ccode" "Leader FE= 68.a1", labels("$\checkmark$" " ")) ///
label se nomtitles title(Controlling for Mismatch between Party and Personal Tenure} \footnotesize \label{table:dif) ///
nonotes addnotes( "Standard errors clustered by country in parentheses.") nogaps nodepvar 





